/**
 * 求数位和，题目强调时限0.5s，所以用了快读快写
 */
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;

namespace IO{

char *__abc147, *__xyz258, __ma369[1000000];
#define __hv007() ((__abc147==__xyz258) && (__xyz258=(__abc147=__ma369)+fread(__ma369,1,100000,stdin),__abc147==__xyz258) ? EOF : *__abc147++)

int getUnsigned(){
	int sgn = 1;
	char ch = __hv007();
	while(ch < '0' || ch > '9') ch = __hv007();
	 
	int ret = (int)(ch-'0');
	while( '0' <= (ch=__hv007()) && ch <= '9' ) ret = ret * 10 + (int)(ch-'0');
	return ret;
}


char __pq981[1000000];
char const * const __rs721 = __pq981 + 1000000;
char * __qw752 = __pq981;

#define __ge(c) (__qw752 == __rs721 ? fwrite(__pq981, 1, 1000000, stdout), __qw752 = __pq981 + 1, *__pq981 = (c) : *__qw752++ = (c))

void putUnsignedEndl(int x){
    if(x == 0) return (void)(__ge('0'));

    char st[25];
	int top = 0;
	while(x){
		st[top++] = x % 10 + '0';
		x /= 10;
	} 
	while(top) __ge(st[--top]);
    __ge('\n');
	return;
}

void finish(){
	fwrite(__pq981, 1, __qw752 - __pq981, stdout);
}

}

int proc(int n){
    int ans = 0;
    while(n){
        ans += n % 10;
        n /= 10;
    }
    return ans;
}

vector<int> Ans;
void init(int n){
    Ans.assign(n + 1, 0);
    for(int i=1;i<=n;++i) Ans[i] = Ans[i - 1] + proc(i);
}

vector<int> Q;


int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    // ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int nofkase = IO::getUnsigned();
    int n = 0;
    Q.assign(nofkase, {});
    for(auto & i : Q) n = max(n, i = IO::getUnsigned());
    init(n);
    for(auto i : Q) IO::putUnsignedEndl(Ans[i]);
    IO::finish();
    return 0;
}